import IconFont from "@/components/IconFont";
import { useConfig } from "@/pages/OrderModule/common/hooks/useConfig";
import { Button, Popconfirm, Popover } from "antd";

import Style from "./index.module.less";
const QueryButton = props => {
	const { item = {}, form, onClear, onClick, quickSearchId, ...args } = props;
	// const {
	//   data = {},
	//   setData,
	//   save,
	//   del,
	// } = useConfig({
	//   code,
	// });

	const confirm = e => {
		e.stopPropagation();
		onClear?.(item?.id);
	};

	return (
		<div
			className={`${Style["tag-wrapper"]} ${quickSearchId == item.id ? Style["tag-selected"] : ""}`}
			{...args}
			onClick={e => {
				if (onClick) {
					form.resetFields();
					form.setFieldsValue(JSON.parse(item?.param || ""));
					onClick?.(item?.id);
				}
			}}
		>
			<Popover content={item?.name}>
				<span className={Style["tag-content"]}>{item?.name}</span>
			</Popover>
			<Popconfirm placement="topLeft" title="确认删除吗？" onConfirm={confirm} okText="确认" cancelText="取消">
				<div className={Style["tag-clear"]} onClick={e => e.stopPropagation()}>
					<IconFont type="iconguanbi2fill" />
				</div>
			</Popconfirm>
		</div>
	);
};

export default QueryButton;
